function PyResult(){
	this.form=this.InitForm();
	this.table=this.InitTableByBt();
}
PyResult.prototype.InitForm=function(){
	var form;
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
	   form.render();
	});  
	return form;
}

PyResult.prototype.InitTableByBt=function (){
	var table;
	var _this=this;
	layui.use('table', function() {
	    table = layui.table;
	    table.init('uatmzpdsummarylist', {
			height : $(window).height() - 100
			,url : 'get_subsidy_list' // 数据接口
			,page : true // 开启分页
			,limit : 30
			,id: 'uatmzpdsummary'
			,method:"post"
				,request:{
					type:'post'
				}
				,where:{
					year: $("#year").val(),
                	mouth:$("#month").val(),
                	orgid:$("#szdw").val()
					}
			    ,done: function(res, page, count){
				    var year = $("#year").val();
				    var month = $("#month").val();
				    var orgname =$("#szdw").text();
                    $("#title").html(orgname+" "+year+" 年  "+month+" 月津贴表");
			    	var dataarr=res.data;
			    	$("[data-field='begintime']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			var begin=(new Date(text)).format("yyyy-MM-dd");
			    			$(this).text(begin);
			    		}
	               })  
	               $("[data-field='endtime']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			var begin=(new Date(text)).format("yyyy-MM-dd");
			    			$(this).text(begin);
			    		}
	              })
	              $("[data-field='year']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			if(text=="0"){
			    				$(this).text($("#year").val());
			    			}
			    			
			    		}
	              }) 
	               
			    }
		  });
	})
	return table;
}



PyResult.prototype.searchtable=function(){
	this.table.reload('uatmzpdsummary', { 
		  page: {
	        curr: 1 //重新从第 1 页开始
	      }
	    ,where: {
            year: $("#year").val(),
            mouth:$("#month").val(),
            orgid:$("#szdw").val()
	    }  
	}); 
}


PyResult.prototype.excle=function(){

}


PyResult.prototype.saveallow=function(){
    var tabledataJson = JSON.stringify(table.cache);
    var year = $("#year").val();
    var month = $("#month").val();
    var orgname =$("#szdw").val();
    tabledataJson = tabledataJson.replace(/LAY_TABLE_INDEX/g,'lay_TABLE_INDEX');
    var uatmzpdsummary  = JSON.parse(tabledataJson);
    uatmzpdsummary['yearid']=year;
    uatmzpdsummary['monthid']=month;
    tabledataJson = JSON.stringify(uatmzpdsummary);
    console.log(tabledataJson);
    $.ajax({
        type:"POST",
        url:"subsidy_pay_save",
        contentType: 'application/json',
        data:tabledataJson,
        beforeSend:function(XHR){

        },
        success:function(data){
            data=eval('('+data+')');
            if(data.result>0){
                top.mylayui.msg(data.msg, {icon: 1});
                document.location.reload();
            }
            else{
                top.mylayui.msg(data.msg, {icon: 0});
            }
        },
        complete:function(XHR){
            var res = XHR.responseText;
            CloseDialog(res)
        },
        error:function(XHR,errorText,errorType){
            var res = XHR.responseText;
            CloseDialog(res,errorText)
        }
    });
}

var vSubsidyPayResult=null;
$(function(){
	vSubsidyPayResult=new PyResult();
})